package com.letcoding.spiderAutoHome.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letcoding.spiderAutoHome.module.CarTest;
import com.letcoding.spiderAutoHome.service.CarTestService;
import com.letcoding.spiderAutoHome.util.TitleFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName TitleFilterConfig
 * @Description 布隆过滤器自动注入
 * @Author will
 * @Date 2021/5/7 10:14
 * @Company 北京华焱坤泰科技有限公司
 */
@Configuration
public class TitleFilterConfig {

    @Autowired
    private CarTestService carTestService;


    @Bean
    public TitleFilter titleFilter() {
        // 创建车辆标题过滤器
        TitleFilter titleFilter = new TitleFilter();
        // 从数据库查询车辆标题，分页查询
        long page = 1;
        long pageSize = 5000;
        boolean repatedFlag = true;
        do {
            Page<CarTest> carTestPage = carTestService.queryTitleByPage(page, pageSize);
            if (!carTestPage.hasNext()) {
                repatedFlag = false;
            }else {
                page += 1;
            }
            for (CarTest record : carTestPage.getRecords()) {
                titleFilter.add(record.getTitle());
            }
        } while (repatedFlag);
        return titleFilter;
    }


}
